# -*- coding: utf-8 -*-

from collections import OrderedDict
from rest_framework.pagination import PageNumberPagination
from rest_framework.settings import api_settings
from rest_framework.response import Response


class PageNumberPagination(PageNumberPagination):
    page_query_param = 'p_index'
    page_size_query_param = 'p_size'

    page_size = api_settings.PAGE_SIZE if api_settings.PAGE_SIZE else 10

    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('p_total', self.page.paginator.count),
            ('p_next', self.get_next_link()),
            ('p_previous', self.get_previous_link()),
            ('data', data)
        ]))
